package kt.hkit.androidcomplete01.chapter08;

import kr.hkit.androidcomplete01.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

public class LongClickEx extends Activity {
	int mCount;
	TextView mTextCount;
	
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.longclickex);
		
		mTextCount = (TextView) findViewById(R.id.ch08_tv_count);
		findViewById(R.id.ch08_btn_decrease).setOnLongClickListener(mLongClickListener);
		findViewById(R.id.ch08_btn_increase).setOnLongClickListener(mLongClickListener);
	}
	
	public void mOnClick(View v){
		switch(v.getId()){
		case R.id.ch08_btn_decrease:
			mCount--;
			mTextCount.setText("" + mCount);
			break;
		case R.id.ch08_btn_increase:
			mCount++;
			mTextCount.setText("" + mCount);
			break;
		}
	}
	
	View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() {
		public boolean onLongClick(View v) {
			switch(v.getId()){
			case R.id.ch08_btn_decrease:
				mCount = 0;
				mTextCount.setText(""+mCount);
				return true;
			case R.id.ch08_btn_increase:
				mCount = 100;
				mTextCount.setText(""+mCount);
				return true;
			}
			return false;
		}
	};
}
